package org.opencv.android;

import android.hardware.Camera;
import android.util.Log;
import java.util.List;

public class CameraRenderer extends CameraGLRendererBase {
    public static final String LOGTAG = "CameraRenderer";
    private Camera mCamera;
    private boolean mPreviewStarted = false;

    CameraRenderer(CameraGLSurfaceView cameraGLSurfaceView) {
        super(cameraGLSurfaceView);
    }

    /* access modifiers changed from: protected */
    @Override // org.opencv.android.CameraGLRendererBase
    public synchronized void closeCamera() {
        Camera camera = this.mCamera;
        if (camera != null) {
            camera.stopPreview();
            this.mPreviewStarted = false;
            this.mCamera.release();
            this.mCamera = null;
        }
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Removed duplicated region for block: B:44:0x00c4  */
    /* JADX WARNING: Removed duplicated region for block: B:45:0x00cc  */
    @Override // org.opencv.android.CameraGLRendererBase
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public synchronized void openCamera(int r7) {
        /*
        // Method dump skipped, instructions count: 337
        */
        throw new UnsupportedOperationException("Method not decompiled: org.opencv.android.CameraRenderer.openCamera(int):void");
    }

    @Override // org.opencv.android.CameraGLRendererBase
    public synchronized void setCameraPreviewSize(int i, int i2) {
        int i3 = i;
        int i4 = i2;
        synchronized (this) {
            Log.i(LOGTAG, "setCameraPreviewSize: " + i3 + "x" + i4);
            if (this.mCamera == null) {
                Log.e(LOGTAG, "Camera isn't initialized!");
                return;
            }
            if (this.mMaxCameraWidth > 0 && this.mMaxCameraWidth < i3) {
                i3 = this.mMaxCameraWidth;
            }
            if (this.mMaxCameraHeight > 0 && this.mMaxCameraHeight < i4) {
                i4 = this.mMaxCameraHeight;
            }
            Camera.Parameters parameters = this.mCamera.getParameters();
            List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
            if (supportedPreviewSizes.size() > 0) {
                float f = ((float) i3) / ((float) i4);
                int i5 = 0;
                int i6 = 0;
                for (Camera.Size size : supportedPreviewSizes) {
                    int i7 = size.width;
                    int i8 = size.height;
                    if (i7 <= i3 && i8 <= i4 && i7 >= i5 && i8 >= i6 && ((double) Math.abs(f - (((float) i7) / ((float) i8)))) < 0.2d) {
                        i6 = i8;
                        i5 = i7;
                    }
                }
                if (i5 <= 0 || i6 <= 0) {
                    i5 = supportedPreviewSizes.get(0).width;
                    i6 = supportedPreviewSizes.get(0).height;
                    Log.e(LOGTAG, "Error: best size was not selected, using " + i5 + " x " + i6);
                } else {
                    Log.i(LOGTAG, "Selected best size: " + i5 + " x " + i6);
                }
                if (this.mPreviewStarted) {
                    this.mCamera.stopPreview();
                    this.mPreviewStarted = false;
                }
                this.mCameraWidth = i5;
                this.mCameraHeight = i6;
                parameters.setPreviewSize(i5, i6);
            }
            parameters.set("orientation", "landscape");
            this.mCamera.setParameters(parameters);
            this.mCamera.startPreview();
            this.mPreviewStarted = true;
        }
    }
}
